package servlet;

import org.json.JSONArray;
import service.UserService;
import service.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author lishunlin110
 */
@WebServlet(name = "ShopListGet", value = "/shoppingList/get")
public class ShopListGetServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/json; charset=utf-8");
        String userId = request.getParameter("u_id");
        PrintWriter out = response.getWriter();
        UserService service = new UserServiceImpl();
        JSONArray array;
        try {
            array = service.getShoppingList(userId);
            if(array==null){
                out.println("暂无数据");
            } else {
                out.println(array);
            }
        } catch (Exception e) {
            e.printStackTrace();
            out.println("系统内部异常");
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
